<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\BelongsTo;
use app\model\not_del\RatingScaleModel as NotDelRatingScaleModel;
use app\model\not_del\UserModel as NotDelUserModel;

/**
 * 任务用户
 */
class TaskUserModel extends BaseModel
{
    protected $name = 'task_user';

    /**
     * 关联用户
     * @return BelongsTo
     */
    public function taskUser(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'user_name' => 'name',
            'age',
            'sex',
            'department_id',
            'username',
            'id_card',
            'phone',
            'avatar',
            'user_number',
            'student_status'
        ]);
    }

    /**
     * 关联量表 - 四合一
     * @return BelongsTo
     */
    public function fourInOneRatingScale(): BelongsTo
    {
        return $this->belongsTo(NotDelRatingScaleModel::class,'rating_scale_id')->bind([
            'rating_scale_previous_name' => 'previous_name',
        ]);
    }

    /**
     * 关联用户-四合一
     * @return BelongsTo
     */
    public function fourInOneUser(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'user_name' => 'name',
            'username',
            'sex',
            'department_id',
            'unit_name'
        ]);
    }

    /**
     * 关联任务用户结果-四合一
     * @return BelongsTo
     */
    public function fourInOneTaskUserResult(): BelongsTo
    {
        return $this->belongsTo(TaskUserResultModel::class,'result_id')->bind([
            'is_valid',
            'question_answer',
            'result_time' => 'time',
            'result_finish_used_time' => 'finish_used_time',
            'TaskFactorScore',
        ]);
    }

    /**
     * 关联任务
     * @return BelongsTo
     */
    public function task(): BelongsTo
    {
        return $this->belongsTo(TaskModel::class,'task_id')->bind([
            'task_name' => 'name',
            'task_start_time' => 'start_time',
            'task_end_time' => 'end_time',
            'result_read_auth',
        ]);
    }

    /**
     * 关联量表
     * @return BelongsTo
     */
    public function ratingScale(): BelongsTo
    {
        return $this->belongsTo(NotDelRatingScaleModel::class,'rating_scale_id')->bind([
            'rating_scale_name'=>'name',
            'rating_scale_cover'=>'cover',
            'rating_scale_mode_id'=>'mode_id',
            'rating_scale_introduce'=>'introduce',
            'rating_scale_notice'=>'notice',
            'use_price',
            'rating_scale_type_name',
            'mode_name',
            'answer_time',
            'read_time',
            'times_time'
        ]);
    }

    /**
     * 关联用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'user_name' => 'name',
            'age',
            'sex',
            'department_id',
            'unit_name'
        ]);
    }

    /**
     * 关联用户
     * @return BelongsTo
     */
    public function user2(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class,'uid')->bind([
            'user_name' => 'name',
            'age',
            'sex',
            'department_id'
        ]);
    }

    /**
     * 关联任务用户结果
     * @return BelongsTo
     */
    public function TaskUserResult(): BelongsTo
    {
        return $this->belongsTo(TaskUserResultModel::class,'result_id')->bind([
            'is_explain',
            'explain',
            'is_warning',
            'warning_id',
            'warning_factor_id',
            'answer_role',
            'is_valid',
            'TaskFactorScore',
            'answer_role',
            'result_read_auth',
            'total_score'
        ]);
    }

    /**
     * 关联任务用户结果
     * @return BelongsTo
     */
    public function TaskUserResult2(): BelongsTo
    {
        return $this->belongsTo(TaskUserResultModel::class,'result_id')->bind([
            'is_explain',
            'is_warning',
        ]);
    }

    /**
     * 关联任务【档案用：任务测评记录列表】
     * @return BelongsTo
     */
    public function getArchivesTask(): BelongsTo
    {
        return $this->belongsTo(TaskModel::class,'task_id')->bind([
            'task_name' => 'name',
            'task_rating_scale_count' => 'rating_scale_count',
        ]);
    }

    /**
     * 关联任务用户结果[档案用：任务测评记录列表]
     * @return BelongsTo
     */
    public function getArchivesTaskResult(): BelongsTo
    {
        return $this->belongsTo(TaskUserResultModel::class,'result_id')->bind([
            'time',
        ]);
    }


}